package com.example.boot_producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.Queue;
import java.util.UUID;

/**
 *
 */
@Component
public class QueueProducer {

    //类似于整合spring中的JmsTemplate
    @Autowired
    JmsMessagingTemplate jmsMessagingTemplate;

    @Resource
    Queue queue;

    public void createMsg(){
        jmsMessagingTemplate.convertAndSend(queue,"****boot 队列消息");
        System.out.println("*******boot发送队列消息完毕");
    }


    //定时发送消息  3s发送一条消息
    @Scheduled(fixedDelay = 3000)
    public void sendMsgSchedule(){
        jmsMessagingTemplate.convertAndSend(queue, UUID.randomUUID().toString().substring(0,5));
        System.out.println("*******boot队列定时发送的消息");
    }
}